<template>
  <!-- 切换店铺 -->
  <view class="chooseshop-content">
    <view
      :class="['chooseshop-item', currentChoose == item.shopId ? 'active' : '']"
      v-for="(item, index) in shopList"
      :key="index"
      @click="chooseShop(item, index)"
    >
      <view class="shop-name">{{ item.name }}</view>
      <view class="shop-address">
        {{ item.address }}
      </view>
      <view class="shop-info">
        <text>{{ item.contactName }}</text>
        <text style="margin-left: 20rpx">{{ item.mobile }}</text>
      </view>
    </view>
  </view>
</template>

<script setup>
import { shopApi } from "@/api";
let shopList = ref([]);
let currentChoose = ref(0);
import { setStorage } from "@/utils/storage";

const chooseShop = (item) => {
  currentChoose.value = item.shopId;
  shopApi.SHOPGETCHANGESHOP({ id: item.shopId }).then((res) => {
    if (res.code == 200) {
      uni.showToast({
        title: res.errMsg,
        icon: "none",
        duration: 1000
      });
      setStorage("shopName", item.name);
      setTimeout(() => {
        uni.switchTab({ url: `/pages/index/index` });
      }, 1000);
    } else {
      uni.showToast({
        title: res.errMsg,
        icon: "none",
        duration: 1000
      });
    }
  });
};

const getShopNameData = () => {
  shopApi.SHOPGETCHANGESHOPLIST().then((res) => {
    if (res.code == 200) {
      shopList.value = res.result;
    } else {
      uni.showToast({
        title: res.errMsg,
        icon: "none",
        duration: 1000
      });
    }
  });
};
onLoad(async () => {
  await getShopNameData();

  shopApi.SHOPGETCURRENTSHOPINFO().then((res) => {
    if (res.code == 200) {
      console.log(res);
    } else {
      uni.showToast({ title: res.errMsg, icon: "none" });
    }
  });
});
</script>
<style>
page {
  background-color: #ededed;
}
</style>
<style lang="scss" scoped>
.chooseshop-content {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24rpx 24rpx 0rpx 24rpx;
  box-sizing: border-box;

  .chooseshop-item {
    width: 100%;
    padding: 8px 16px 8px 16px;
    border-radius: 8px;
    box-sizing: border-box;
    background-color: #fff;
    margin-bottom: 24rpx;
    // .item-tit {
    //   font-family: PingFang SC;
    //   font-size: 14px;
    //   font-weight: 600;
    //   line-height: 22px;
    //   text-align: left;
    //   color: rgba(0, 0, 0, 0.9);
    // }
    // .item-address {
    //   font-family: PingFang SC;
    //   font-size: 12px;
    //   font-weight: 400;
    //   line-height: 20px;
    //   text-align: left;
    //   color: rgba(0, 0, 0, 0.6);
    // }
    .shop-name {
      font-size: 28rpx;
      font-weight: 600;
      margin-bottom: 5rpx;
      line-height: 50rpx;
    }
    .shop-address {
      line-height: 20rpx;
      font-size: 24rpx;
      font-weight: 400;
      line-height: 40rpx;
    }
    .shop-info {
      display: flex;
      align-items: center;
      font-size: 24rpx;
      font-weight: 400;
      line-height: 40rpx;
    }
  }
  .active {
    border: 1rpx solid rgba(214, 142, 68, 1);
  }
}
</style>
